def add_sprite():
""" Adds a player to the stage for the user to control """
person = codesters.Sprite("person3",0,-155)
return person
def add_numbers(a, b):
"""Add two numbers together and return the answer"""
answer = a + b
return answer
def main():
""" Sets up the program and calls other functions """
person = add_sprite()
num1 = int(person.ask("Enter a number"))
num2 = int(person.ask("Enter a 2nd number"))
sum = add_numbers(num1, num2)
person.say("The sum is " + str(sum))
main()
stage.wait(3)
question1 = MCQ(1,"","","","","","", "row")
question1.set_prompt(" 1) What is the return variable for the add_numbers function?")
question1.set_choice_A("person")
question1.set_choice_B("answer")
question1.set_choice_C("sprite")
question1.set_choice_D("number")
question1.set_correct("B")
question2 = MCQ(2,"","","","","","", "row")
question2.set_prompt("2) What is true about a docstring?")
question2.set_choice_A("Docstrings start with a #")
question2.set_choice_B("Docstrings are grey")
question2.set_choice_C("Docstrings start and end with 3 quotes")
question2.set_choice_D("Docstrings are blue")
question2.set_correct("C")
question3 = MCQ(3,"","","","","","", "row")
question3.set_prompt("3) Why do we use a main function in a program?")
question3.set_choice_A("To make sure the program will run")
question3.set_choice_B("To specify what the most important function is")
question3.set_choice_C("To call less important functions in our program")
question3.set_choice_D("To organize the code and make it more readable")
question3.set_correct("D")
repeat_test = True
stop_test = False
def test_script():
global repeat_test
global stop_test
try:
tval1 = question1.correct
except:
tval1 = "DNE"
try:
tval2 = question2.correct
except:
tval2 = "DNE"
try:
tval3 = question3.correct
except:
tval3 = "DNE"
t1 = TestObjective()
t1.add_success(tval1 == True, " ")
t1.add_failure(tval1 == False, "Q1 wrong")
t1.add_failure(tval1 == "DNE", " ")
t2 = TestObjective()
t2.add_success(tval2 == True, " ")
t2.add_failure(tval2 == False, "Q2 wrong")
t2.add_failure(tval2 == "DNE", " ")
t3 = TestObjective()
t3.add_success(tval3 == True, " ")
t3.add_failure(tval3 == False, "Q3 wrong")
t3.add_failure(tval3 == "DNE", " ")
tester = TestManager()
tester.add_test_list([t1, t2, t3])
tester.run_tests()
#tester.display_first_feedback()
if repeat_test == False:
stop_test = True
test_counter = 0
def repeat_tests():
global stop_test
global test_counter
if stop_test == False:
test_script()
if test_counter >= 100:
stop_test = True
stage.event_interval(repeat_tests, .2)
-
Run Code
-
Activity Submitted!
Enviar Trabajo
-
Actividad Siguiente
-
Stop Running Code
-
Show Chart
-
Show Console
-
Reset Code Editor
-
Codesters How To (opens in a new tab)